package com.txzt.gaea.common.exception;

import com.txzt.base.core.RtnInfo;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Order(-1)
@Component
public class CustomerHandlerExceptionResolver implements HandlerExceptionResolver {

    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object o, Exception e) {
        e.printStackTrace();
        try {
            response.setContentType("application/json;charset=utf-8");
            response.sendError(RtnInfo.SERVER_ERROR.getCode(),e.getMessage());
        }catch (Exception ex){
            ex.printStackTrace();
        }
        ModelAndView mv = new ModelAndView();
        mv.addObject("exceptionMsg", e.getMessage());
        mv.setViewName("exception");
        return new ModelAndView();
    }
}
